<div class="content">

   	<div class="list_button">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
        <tr>
            <td>
                <?php
				
					echo CHtml::link(
						"<div class='button'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-plus.png") .
							"</div>" .
							"<div style='float:left; width:80px;'>".
								"Thêm mới" .
							"</div>" .
						"</div>"
						,
                       array($this->controller_id."/add",
					   	"menu_id"=>$menu_id, "language_id"=> $language_id)
                    );
					
					echo "<div class='button' id='delete_multi'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-remove.png") .
							"</div>" .
							"<div style='float:left; width:40px;'>".
								"Xóa" .
							"</div>" .
						"</div>";
                ?>
                <script language="javascript">
                $(document).ready(function(){
                    $('#delete_multi').click(function(){
                        var form = document.getElementById("form_table_all");
                        form.submit();
                    });	
                })
              </script>
            </td>
            
            <td align="right">
                <?php
                    $list_menu = array();
                    $list_menu[0] = "-- Menu --";
                    $menus = menu::model()->findAll(array("order"=>"`order` ASC"));
                    if (!is_null($menus))
                    {
                        foreach($menus as $menu)
                        {
                            $list_menu[$menu["id"]] = $menu["name"];
                        }
                    }
                    
                    echo CHtml::dropDownList("menu_id",$menu_id, $list_menu,
                        array("id"=>"menu_id", "style"=>"margin:0"));
            
                ?>
                  <script language="javascript">
                    $(document).ready(function(){
                        $('#menu_id').change(function(){
                            <?php
                                $url = Yii::app()->createUrl($this->getUniqueId()."/view");
                            ?>
							var language_id = document.getElementById('language_id');
                            var url = '<?php echo $url; ?>' + 
								"&menu_id=" + this.value + "&language_id=" + language_id.value;
                            window.location = url;
                        });	
                    })
                  </script>
                  
                 <?php
				 	//Ngôn ngữ
				 	$list_language = array();
                    $list_language[0] = "-- Ngôn ngữ --";
                    $languages = language::model()->findAll(array("order"=>"`order` ASC"));
                    if (!is_null($languages))
                    {
                        foreach($languages as $language)
                        {
                            $list_language[$language["id"]] = $language["name"];
                        }
                    }
                    
                    echo CHtml::dropDownList("language_id",$language_id, $list_language,
                        array("id"=>"language_id", "style"=>"margin:0"));
				 ?>
                 
                 <script language="javascript">
                    $(document).ready(function(){
                        $('#language_id').change(function(){
                            <?php
                                $url = Yii::app()->createUrl($this->getUniqueId()."/view");
                            ?>
							var menu_id = document.getElementById('menu_id');
                            var url = '<?php echo $url; ?>' + 
								"&menu_id=" + menu_id.value + "&language_id=" + this.value;;
                            window.location = url;
                        });	
                    })
                  </script>
             </td>
          </tr>
        </table>
	</div>

    <table class="view">
        <tr height='25'>
            <th width="50px"> # </th>
            <th width="30">
                <?php 
                    echo CHtml::checkBox("checkbox_all", false, array("id"=>"checkbox_all"));
                ?>
            </th>
            <th colspan="2">Action</th>
            <th>Menu Item</th>
            <th width="80">Bật / Tắt</th>
            <th width="80">Mặc định</th>
            <th width="80">
            	<?php 
					echo CHtml::link(
						"Thứ tự",
						array($this->controller_id."/set_order", 
							"menu_id"=>$menu_id, "language_id"=>$language_id),
						array("title"=>"Tạo thứ tự mặc định")
					);
					echo " ";
					echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-saveorder.png", "", 
						array("style"=>"cursor:pointer", "id"=>"id_save_order"));

				?>
                <script language="javascript">
					$(document).ready(function(){
						$('#id_save_order').click(function() {
							var url = '<?php 
								$url = Yii::app()->createUrl(
									$this->route."/save_order",
									array("menu_id"=>$menu_id, "language_id"=>$language_id)
								);
								echo $url;
							?>';
							var form = document.getElementById("form_table_all");
							form.action = url;
							//alert(form.action);
							form.submit();
						});
					});
				</script>
            </th>
            <th width="120">Alias</th>
            <th width="120">Params</th>
            <th width="120">Parrent</th>
            <th width="100">Menu</th>
            <th width="50">ID</th>
        </tr>
        <?php
            if (! is_null($rows))
            {
                echo CHtml::beginForm(
					array($this->controller_id."/delete_multi", 
						"menu_id"=>$menu_id
					),
					"post",
                    array("id"=>"form_table_all")
				);
                
                $i = 1;
                foreach($rows as $row)
                {
                    echo "<tr height='25'>";
                        echo "<td align='center'>";
                            echo $i++;
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo CHtml::checkBox("cib[".$row["id"]."]", false, array("id"=>"cb".$i));
                        echo "</td>";
                        
                        echo "<td width='26px' align='center'>";
						
							$url = Yii::app()->createUrl(
								$this->route."/delete",
								array(
									"menuitem_id" => $row["id"],
									"menu_id" => $menu_id,
									"language_id" => $language_id
								)
							);
							
							echo CHtml::image(
								Yii::app()->baseUrl.'/assets/icon/icon-16-trash.png',
								"",
								array(
									"style"=>"cursor:pointer",
									"title"=>"Delete",  
									"onClick"=>"javascript:actionDelete('".$url."');"
								)
							);
							
                        echo "</td>";
                        
                        echo "<td width='26px' align='center'>";
                            echo CHtml::link(
                                CHtml::image(Yii::app()->baseUrl.'/assets/icon/icon-16-edit.png'),
                                array(
                                    $this->controller_id."/edit",
                                    "menuitem_id" => $row["id"],
                                    'menu_id' => $menu_id,
									"language_id" => $language_id
                                ),
                                array('title'=>'edit')
                            );
                        echo "</td>";
                            
                        echo "<td>";
							if ($row->parent_id > 0)
								echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-triangle.png");
                            echo CHtml::link(
                                $row["name"],
                                array(
                                    $this->controller_id."/edit",
                                    'menuitem_id' => $row["id"],
                                    'menu_id' => $menu_id,
									"language_id" => $language_id
                                ),
                                array('title'=>'Edit')
                            );
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            $icons =  array(
                                0 => "icon-16-remove.png",
                                1 => "icon-16-tick.png",
                            );
                            echo CHtml::link(
                                CHtml::image(Yii::app()->baseUrl.'/assets/icon/'.$icons[$row["enable"]]),
                                array($this->controller_id."/enable", 
                                    "menuitem_id"=>$row["id"],
                                    "menu_id" =>$menu_id,
									"language_id" => $language_id
                                )
                            );
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            $icons =  array(
								0 => "icon-16-nondefault.png",
								1 => "icon-16-default.png",
							);
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl.'/assets/icon/'.$icons[$row["default"]]),
								array(
									$this->controller_id."/default", 
									"menuitem_id"=>$row["id"],
                                    "menu_id" =>$menu_id,
									"language_id" => $language_id
								)
							);
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo CHtml::textField(
								"order[".$row->id."]",
								$row->order,
								array("style"=>"width:50px; text-align:right; 
									padding:3px; color:#f00; font-size:11px;")
							);
                        echo "</td>";
                        
						echo "<td>";
                           echo $row->alias;
                        echo "</td>";
						
						echo "<td>";
                           echo $row->params;;
                        echo "</td>";
						
						echo "<td>";
                           	$menuitem_parent = menuitem::model()->findByPk($row->parent_id);
						   	if (is_null($menuitem_parent))
							{
								echo "<span style='color:#f00;'>";
						   		echo "NULL";
								echo "</span>";
							}
							else
								echo $menuitem_parent->name;
                        echo "</td>";
                        
						
                        echo "<td>";
                            $menu = menu::model()->findByPk($row->menu_id);
							if (is_null($menu))
							{
								echo "<span style='color:#f00;'>";
						   		echo "NULL";
								echo "</span>";
							}
							else
								echo $menu->name;
                        echo "</td>";
                        
                        echo "<td align='center'>";
                            echo $row["id"];
                        echo "</td>";
                    echo "</tr>";        
                }
                
                echo CHtml::endForm(); // end form
            }
        ?>
    </table>
</div><!-- end div content -->

<script language="javascript">
function actionDelete(url)
{	
	if (confirm("Bạn muốn xóa mẫu tin này ?") == true)
		window.location = url;
}
</script>